package com.ruoyi.project.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.ProjectCompleted;
import com.ruoyi.project.service.IProjectCompletedService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 完成项目Controller
 * 
 * @author czj
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/completed")
public class ProjectCompletedController extends BaseController
{
    @Autowired
    private IProjectCompletedService projectCompletedService;

    /**
     * 查询完成项目列表
     */
    @RequiresPermissions("project:completed:list")
    @GetMapping("/list")
    public TableDataInfo list(ProjectCompleted projectCompleted)
    {
        startPage();
        List<ProjectCompleted> list = projectCompletedService.selectProjectCompletedList(projectCompleted);
        return getDataTable(list);
    }

    /**
     * 导出完成项目列表
     */
    @RequiresPermissions("project:completed:export")
    @Log(title = "完成项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectCompleted projectCompleted)
    {
        List<ProjectCompleted> list = projectCompletedService.selectProjectCompletedList(projectCompleted);
        ExcelUtil<ProjectCompleted> util = new ExcelUtil<ProjectCompleted>(ProjectCompleted.class);
        util.exportExcel(response, list, "完成项目数据");
    }

    /**
     * 获取完成项目详细信息
     */
    @RequiresPermissions("project:completed:query")
    @GetMapping(value = "/{completionId}")
    public AjaxResult getInfo(@PathVariable("completionId") Long completionId)
    {
        return success(projectCompletedService.selectProjectCompletedByCompletionId(completionId));
    }

    /**
     * 新增完成项目
     */
    @RequiresPermissions("project:completed:add")
    @Log(title = "完成项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectCompleted projectCompleted)
    {
        return toAjax(projectCompletedService.insertProjectCompleted(projectCompleted));
    }

    /**
     * 修改完成项目
     */
    @RequiresPermissions("project:completed:edit")
    @Log(title = "完成项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectCompleted projectCompleted)
    {
        return toAjax(projectCompletedService.updateProjectCompleted(projectCompleted));
    }

    /**
     * 删除完成项目
     */
    @RequiresPermissions("project:completed:remove")
    @Log(title = "完成项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{completionIds}")
    public AjaxResult remove(@PathVariable Long[] completionIds)
    {
        return toAjax(projectCompletedService.deleteProjectCompletedByCompletionIds(completionIds));
    }
}
